<template>
  <div class="app-container">
    <!-- 订单审核对话框 -->
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <div>
          <!-- <i class="MmsUiBlockTitle___line___27lhp1-44-1"></i> -->
          <div class="big_title_style" style="font-size: 18px">
            <span>订单信息</span>
          </div>
          <el-divider></el-divider>
          <div>
            <el-row>
              <el-col :span="12">
                <el-form-item label="结算单号">
                  <span>{{ showData.settlementNo }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="订单数量">
                  <span>{{ showData.orderNumber }}</span>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
            </el-row>
            <el-row>
              <el-col :span="12">
                <el-form-item label="售后金额">
                  <span>{{ showData.serviceAmountTotal }} 元</span>
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="结算金额">
                  <span>{{ showData.settlementMoney }} 元</span>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
          <div style="margin-left: 50px">
            <template>
              <el-table
                border
                :data="tableData"
                height="400"
                :summary-method="getSummaries"
                show-summary
                style="width: 100%; margin-top: 20px">
                <el-table-column
                  prop="orderNo"
                  label="订单编号"
                  width="150">
                </el-table-column>
                <el-table-column
                  prop="proName"
                  label="商品名称"
                  width="150">
                </el-table-column>
                <el-table-column
                  prop="skuDesc"
                  label="商品描述"
                  width="140">
                </el-table-column>
                <el-table-column
                  prop="costPrice"
                  label="供应价格（元）"
                  width="120">
                </el-table-column>
                <el-table-column
                  prop="itemNumber"
                  label="销售数量"
                  width="100">
                </el-table-column>
                <el-table-column
                  prop="serviceNumber"
                  label="售后数量"
                  width="100">
                </el-table-column>
                <el-table-column
                  prop="serviceAmount"
                  label="售后金额（元）"
                  width="120">
                </el-table-column>
                <el-table-column
                  prop="settlementAmount"
                  label="结算金额（元）"
                  width="120">
                </el-table-column>
                <el-table-column
                  prop="payTime"
                  label="下单时间"
                  width="170">
                </el-table-column>
              </el-table>
            </template>
          </div>
        </div>

        <div style="margin-top: 60px">

          <el-form-item label="审核意见">
            <el-input type="textarea" v-model="form.auditMsg"></el-input>
          </el-form-item>
          <div slot="footer" class="dialog-footer" style="margin-left: 80%">
            <el-button type="primary" @click="submitForm(1)">同 意</el-button>
            <el-button @click="submitForm(-1)">拒 绝</el-button>
          </div>

        </div>
      </el-form>
  </div>
</template>

<script>

  import {
    getSettlementDetailById
  } from '@/api/supplier/settlement'
  import {
    updateAudit
  } from '@/api/supplier/settlement'
  export default {
    name: 'Settlement',
    components: {},
    data() {
      return {
        title: "订单审核",
        form: {},
        // 表单校验
        rules: {},
        //订单详细数据
        tableData: [],
        //订单信息
        showData: [],
        //自动撑开表格
        fit: true,
        //表格合计
        summary: true
      }
    },
    props: {
      //是否显示
      viewOpen: {
        type: Boolean,
        default: false,
      },
      //是否显示
      auditSettlementIdStr: {
        type: Number,
        default: null,
      },
    },
    created() {
      if (this.auditSettlementIdStr) {
        this.getOrderDetailById(this.auditSettlementIdStr)
      }
    },
    methods: {
      getSummaries(param) {
        const {columns, data} = param;
        const sums = [];
        columns.forEach((column, index) => {
          if (index === 0) {
            sums[index] = '总价';
            return;
          }
          const values = data.map(item => Number(item[column.property]));
          if (!values.every(value => isNaN(value))) {
            sums[index] = values.reduce((prev, curr) => {
              const value = Number(curr);
              if (!isNaN(value)) {
                return prev + curr;
              } else {
                return prev;
              }
            }, 0);
            sums[index];
          } else {
            sums[index] = 'N/A';
          }
        });

        return sums;
      },
      /** 提交操作 */
      submitForm(row) {
          updateAudit(this.form.settlementId,this.form.auditMsg,row).then((response) => {
            this.msgSuccess('审核成功')
            this.$emit("update:auditViewOpenStr", false);
            this.$emit('getList');
          })

      },

      //查询订单详细
      getOrderDetailById(row) {
        getSettlementDetailById(row).then(response => {
          this.tableData = response.orderSettlementVos;
          this.showData = response;
          this.form = response
        })
      },


    }
  }
</script>
<style scoped>
  .MmsUiBlockTitle___line___27lhp1-44-1 {
    display: inline-block;
    background: #407cff;
    width: 2px;
    height: 16px;
    margin-right: 8px;
  }

  .MmsUiBlockTitle___title___2C-H-1-44-1 {
    display: inline-block;
    font-size: 20px;
    color: #333;
    position: relative;
  }
  .el-table {
    overflow: visible !important;
  }
</style>
